postRequest("js/postTemplate.php", "", function(request) {
	postTemplate = request.responseText;
});

function printPosts(request) {
	var response = JSON.parse(request.responseText);
	// = eval('('+request.responseText +')');
	var str = "";
	if (response.length > 0) {
		for (x in response) {
			var post = response[x];
			var views = post.views;
			var user = post.userid;
			var date = post.date;
			var postid = post.postid;
			var subject = post.subject;
			var content = post.content;
			// this will be snippeted if called with parameter
			var rating = post.rating;
			var votes = post.numberofratings;
			var img = post.img;
			var hate = ["","","","",""];
			hate[rating-1] = "selected:'selected'";
			str = eval('"' + postTemplate + '"');
		}
		// needs if statements here so it doesn't make divs and stuff if nothing
		// in response
		var content = document.getElementById("content");
		content.innerHTML = str + content.innerHTML;
		// content.insertBefore(str, content.firstChild);//todo this I need to
		// document.create and stuff
		// should probably be posts id so it doesn't fuckup on other pages

	}
}

function getLatest() {
	node = document.getElementById("content").firstChild;
	while (node.nodeType != 1) {
		node = node.nextSibling;
	}
	return node.id;
}

function getNew() {
	postRequest("api/post/new.php", "latest=" + getLatest(), printPosts);
}
// check if new
// get new
function refresh() {
	postRequest("api/post/view.php", "amount=2", printPosts);
}